<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getTotalTime(list = []) {
        if (list.length === 0) {
          return 0
        }
        if (list.length === 1) {
          return list[0]
        }
        // 代表当前项的最优解
        const dp = [list[0], Math.max(list[0], list[1])]

        for (let i = 2; i < list.length; i++) {
          // 当前预约的两个选择，一个是接，一个是不接
          dp[i] = Math.max(list[i] + dp[i - 2], dp[i - 1])
        }
        console.log(dp)
      }
      getTotalTime([4, 6, 8, 6, 2, 3, 4, 5])
    </script>
  </body>
</html>
